from rest_framework import serializers
from app.models import Navbar,Movie


class NavSerializer(serializers.ModelSerializer):
    class Meta:
        model = Navbar
        fields = ('id','title','url')


class FilmSerializer(serializers.ModelSerializer):
    # filmId = serializers.IntegerField(source="filmId")
    class Meta:
        model = Movie
        fields = ('__all__')

    actor_list = serializers.SerializerMethodField()
    photos_list = serializers.SerializerMethodField()

    def get_actor_list(self,m):
        # 拿到queryset开始循环
        actors = list()

        for actor in m.actors_set.all():
            info = {"name":actor.name,"role":actor.get_role_display(),"img":actor.img,}
            actors.append(info)
        return actors

    def get_photos_list(self,photos):
        photo_list = list()
        for photo in photos.stagephoto_set.all():
            photo_list.append(photo.img)
        return photo_list


class ComingFilmSerializer(FilmSerializer):
    show_date = serializers.DateTimeField()

